package m2_work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //连接
        ConnectionFactory cf = new ConnectionFactory();
        cf.setHost("192.168.126.130");
        cf.setUsername("admin");
        cf.setPassword("admin");
        //建立连接通道
        Channel channel = cf.newConnection().createChannel();
        //定义队列
        channel.queueDeclare("task-queue", true, false, false, null);
        //发消息
        while (true) {
            System.out.println("输入消息:");
            String msg = new Scanner(System.in).nextLine();
            channel.basicPublish("", "task-queue", MessageProperties.PERSISTENT_TEXT_PLAIN, msg.getBytes());
        }
    }
}
